package com.hdsx.jxcsxm.log.factory;

import com.hdsx.jxcsxm.log.bean.SysLog;
import com.hdsx.jxcsxm.log.strategy.IOperatStrategy;
import com.hdsx.jxcsxm.log.strategy.impl.*;
import com.hdsx.jxcsxm.log.type.BusinessType;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 占贤银
 * time 2023/8/18 9:10
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
public final class OperateStrategyFactory {

    private static Map<String, IOperatStrategy> strategyMap =
            new ConcurrentHashMap<String, IOperatStrategy>(20);

    static {
        strategyMap.put(BusinessType.Flag.LOGIN, new LoginOperatStrategy());
        strategyMap.put(BusinessType.Flag.JHCX, new JhcxOperatStrategy());
        strategyMap.put(BusinessType.Flag.ZJDW, new ZjdwOperatStrategy());
        strategyMap.put(BusinessType.Flag.ZJBF, new ZjbfOperatStrategy());
        strategyMap.put(BusinessType.Flag.XMZJTJ, new ZjtjOperatStrategy());
        strategyMap.put(BusinessType.Flag.XMZJTJXM, new ZjtjXmOperatStrategy());
        strategyMap.put(BusinessType.Flag.XMZJZH, new ZjtjXmzhOperatStrategy());
        // 添加
        strategyMap.put(BusinessType.Flag.INSERT_TYPE, new AddXmOperatStrategy());
        strategyMap.put(BusinessType.Flag.DELETE_TYPE, new DeleteXmOperatStrategy());
        strategyMap.put(BusinessType.Flag.UPDATE_TYPE, new UpdateXmOperatStrategy());
        strategyMap.put(BusinessType.Flag.UPDATEZJDWTYPE, new UpdateTypeStrategy());
    }

    public static SysLog getOperaStrategy(ActionInvocation invocation,
                                          HttpServletRequest request){
        final ActionContext ac = invocation.getInvocationContext();
        final String requestURI = request.getRequestURI();
        SysLog sysLog = null;
        if (requestURI.matches("\\D*(xtgl/enterLogin.do)")) {
            sysLog = strategyMap.get(BusinessType.Flag.LOGIN).operate(invocation, request);
        } else if (requestURI.matches("\\D*(jhcx/queryXmlist.do|/funds/queryXmlist.do)")) {
            sysLog = strategyMap.get(BusinessType.Flag.JHCX).operate(invocation, request);
        } else if (requestURI.matches("\\D+(zjdw/queryXmlist.do|/funds/zjdw/queryXmlist)")) {
            sysLog = strategyMap.get(BusinessType.Flag.ZJDW).operate(invocation, request);
        } else if (requestURI.matches("\\D*(zjbf/queryXmlist.do|/funds/zjbf/queryXmlist)")) {
            sysLog = strategyMap.get(BusinessType.Flag.ZJBF).operate(invocation, request);
        } else if (requestURI.matches("\\D*(zjtj/queryXmlist.do)")) {
            sysLog = strategyMap.get(BusinessType.Flag.XMZJTJ).operate(invocation, request);
        } else if (requestURI.matches("\\D*(zjtj/queryTjXmlist.do)")) {
            sysLog = strategyMap.get(BusinessType.Flag.XMZJTJXM).operate(invocation, request);
        } else if (requestURI.matches("\\D*(zjtj/queryWjhXmlist.do)")) {
            sysLog = strategyMap.get(BusinessType.Flag.XMZJZH).operate(invocation, request);
        } else if (requestURI.matches("\\D*(/zjdw/insertZjdw.do|/zjbf/insertZjbf.do)")) {
            sysLog = strategyMap.get(BusinessType.Flag.INSERT_TYPE).operate(invocation, request);
        } else if (requestURI.matches("\\D*(/zjdw/deldw.do)")) {
            // todo 删除
            sysLog = strategyMap.get(BusinessType.Flag.DELETE_TYPE).operate(invocation, request);
        } else if (requestURI.matches("\\D*(/zjdw/updateZjdw.do)")) {
            // todo 修改
            sysLog = strategyMap.get(BusinessType.Flag.UPDATE_TYPE).operate(invocation, request);
        } else if (requestURI.matches("\\D*(/zjdw/updateZjdwType.do)")) {
            sysLog = strategyMap.get(BusinessType.Flag.UPDATEZJDWTYPE).operate(invocation, request);
        }
        return sysLog;
    }
}
